<?php
// src/Asiah/SiklusBundle/Entity/User.php
namespace Asiah\SiklusBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
/**
 * @ORM\Entity(repositoryClass="Asiah\SiklusBundle\Repository\UserRepository")
 * @ORM\Table(name="user")
 */

class User implements UserInterface {

	public function __construct(){
		$this->userRoles = new ArrayCollection();
		$this->join_date = new \DateTime();
		$this->salt = md5(time()); 
	}
	/**
	 * @ORM\Id
	 * @ORM\Column(type="integer")
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	protected $id;
	/**
	 * @ORM\Column(type="string", length="50")
	 */
	protected $name;
	/**
	 * @ORM\Column(type="string", unique=true, length="20")
	 */
	protected $username;
	/**
	 * @ORM\Column(type="string")
	 */
	protected $password;
	/**
	 * @ORM\Column(type="string")
	 */
	protected $email;
	/**
	 * @ORM\Column(type="string", length="255")
	 *
	 * @var string salt
	 */
	protected $salt;
	/**
	 * @ORM\Column(type="date")
	 */
	protected $join_date;
	/**
	 * @ORM\ManyToMany(targetEntity="Role")
	 * @ORM\JoinTable(name="user_role",
	 *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
	 *     inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
	 * )
	 *
	 * @var ArrayCollection $userRoles
	 */
	protected $userRoles;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set username
     *
     * @param string $username
     */
    public function setUsername($username)
    {
        $this->username = $username;
    }

    /**
     * Get username
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     */
    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set email
     *
     * @param string $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set salt
     *
     * @param string $salt
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;
    }

    /**
     * Get salt
     *
     * @return string 
     */
    public function getSalt()
    {
        return $this->salt;
    }

    /**
     * Set join_date
     *
     * @param date $joinDate
     */
    public function setJoinDate($joinDate)
    {
        $this->join_date = $joinDate;
    }

    /**
     * Get join_date
     *
     * @return date 
     */
    public function getJoinDate()
    {
        return $this->join_date;
    }

    /**
     * Add userRoles
     *
     * @param Asiah\SiklusBundle\Entity\Role $userRoles
     */
    public function addRole(\Asiah\SiklusBundle\Entity\Role $userRoles)
    {
        $this->userRoles[] = $userRoles;
    }

    /**
     * Get userRoles
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getUserRoles()
    {
        return $this->userRoles;
    }
    /**
	* Erases the user credentials.
	*/
    public function eraseCredentials()
    {

    }
    /**
	* Gets an array of roles.
	* 
	* @return array An array of Role objects
	*/
    public function getRoles()
    {
	    return $this->getUserRoles()->toArray();
    }

    /**
	* Compares this user to another to determine if they are the same.
	* 
	* @param UserInterface $user The user
	* @return boolean True if equal, false othwerwise.
	*/
    public function equals(UserInterface $user)
    {
	    return md5($this->getUsername()) == md5($user->getUsername());
    }
}
